package 线程.综合练习.多线程之间的比较;

import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Text {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //定义一个奖池的对象
        ArrayList<Integer> list=new ArrayList<>();
        Collections.addAll(list,10,5,20,50,100,200,500,800,2,80,300,700);
        //创建线程任务类对象
        MyFun mf=new MyFun(list);

        //创建管理线程任务类的对象
        FutureTask<Integer> ft1=new FutureTask<>(mf);
        FutureTask<Integer> ft2=new FutureTask<>(mf);

        //创建线程的对象
        Thread t1=new Thread(ft1);
        Thread t2=new Thread(ft2);

        //设置线程的名字
        t1.setName("抽奖池1");
        t2.setName("抽奖池2");

        //启动线程
        t1.start();
        t2.start();

        //获取线程的结果
        Integer num1 = ft1.get();
        Integer num2 = ft2.get();
        System.out.println(num1);
        System.out.println(num2);
    }
}